<?php

namespace app\api\controller\ai;

use app\common\controller\Api;
use think\Request;

class Base extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    protected $service;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
    }

    public function create()
    {
        $input = $this->request->post();
        $id = $this->service->create($input['model'], $input['prompt']);
        $this->success('请求成功', (int)$id, 200);
    }

    public function history()
    {
        $input = $this->request->post();
        $data = $this->service->history($input['model'], $input['page'] ?? 1, $input['pageSize'] ?? 20);
        $this->success('请求成功',$data, 200);
    }

    public function conversationHistory()
    {
        $input = $this->request->post();
        $data = $this->service->conversationHistory($input['chatId'], $input['lastId'] ?? 0, $input['pageSize'] ?? 20);
        $this->success('请求成功',$data, 200);
    }

    public function completions()
    {
        $input = $this->request->param();
        $this->service->completions($input['id'], $input['model'], $input['prompt'], $input['img'] ?? [], $input['deepThink'], $input['webSearch']);
    }
}